/** Unit test program to test the EventProcessor and Messaging capablities */

// how many generators are started
#define NUM_GENERATORS 2 
#define NUM_WORKERS 10
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>

#include "Master.h"
#include "Generator.h"
#include "DistributedCounter.h"
#include "TwoWayList.cc"

int main(void){
	
  Master master;
  master.ForkAndSpin(); 

  DistributedCounter dCounter(NUM_GENERATORS);
	
  DistributedCounter dCounterW(NUM_WORKERS);

#if 1 
  TwoWayList <EventProcessor> myWorkers;
  for (int i=0; i<NUM_WORKERS; ++i) {
    Worker newWorker(master, dCounterW);
    newWorker.ForkAndSpin();
    myWorkers.Insert(newWorker);
  }
#endif

  TwoWayList <EventProcessor> myGens;
  for (int i=0; i<NUM_GENERATORS; ++i) {
    Generator newGen(master, dCounter);
    newGen.ForkAndSpin();
    myGens.Insert(newGen);
  }
  master.WaitForProcessorDeath(); 
  int result = NUM_GENERATORS*REPETITIONS*(REPETITIONS+1)/2; 
  cout<<"The correct outcome : "<<result<<endl;
  return 0;
}
